<?php
   
	class MyCalculation
	{
		private function ageScore($age)
		{     
			if(($age >= 21) && ($age <= 50))
			{
				$agePoint = 3;
			}
			elseif(($age >= 51) && ($age <= 60))
			{
				$agePoint = 2;
			}
			elseif($age > 60)
			{
				$agePoint = 1;
			}
			else
			{
				$agePoint = "error";
			}
             console.log('$age  ' + $age);
             console.log('$age cal ' + $agePoint);
			return $agePoint;
		}

		private function martialScore($martial_status)
		{
			if($martial_status == "single")
			{
				$martialPoint = 2;
			}
			elseif($martial_status == "married")
			{
				$martialPoint = 3;
			}
			elseif(($martial_status == "separated")||($martial_status == "divorced")||($martial_status == "defacto"))
			{
				$martialPoint = 1;
			}
			else
			{
				$martialPoint = "error";
			}
			return $martialPoint;
		}

		/*private function dependantScore($num_of_dc)
		{
			if(($num_of_dc >= 0) && ($num_of_dc <= 2))
			{
				$dcPoint = 2;
			}
			elseif($num_of_dc > 2)
			{
				$dcPoint = 1;
			}
			else
			{
				$dcPoint = "error";
			}
		}*/

		private function housingScore($residential_status)
		{
			if($residential_status == "self_owned")
			{
				$housingPoint = 3;
			}
			elseif($residential_status == "mortgaged")
			{
				$housingPoint = 2;
			}
			elseif(($residential_status == "company_house")||($residential_status == "renting")||($residential_status == "livewithparent")||($residential_status == "other"))
			{
				$housingPoint = 1;
			}
			else
			{
				$housingPoint = "error";
			}
		}

		private function incomeScore($employment_status)
		{
			if($employment_status == "fulltime")
			{
				$incomePoint = 3;
			}
			elseif(($employment_status == "partime")||($employment_status == "casual")||($employment_status == "contractor")||($employment_status == "self_employed")||($employment_status == "not_employed"))
			{
				$incomePoint = 2;
			}
			else
			{
				$incomePoint = "error";
			}
			return $incomePoint;
		}

		private function salaryScore($gross_salary_applicant_1)
		{
			if(($gross_salary_applicant_1 >= 500) && ($gross_salary_applicant_1 <= 1500))
			{
				$salaryPoint = 1;
			}
			elseif(($gross_salary_applicant_1 >= 1501) && ($gross_salary_applicant_1 <= 2500))
			{
				$salaryPoint = 2;
			}
			elseif(($gross_salary_applicant_1 >= 2501) && ($gross_salary_applicant_1 <= 3500))
			{
				$salaryPoint = 3;
			}
			elseif($gross_salary_applicant_1 >= 3501)
			{
				$salaryPoint = 4;
			}
			else
			{
				$salaryPoint = "error";
			}
			return $salaryPoint;
		}

		private function occupationScore($employment_level)
		{
			if($employment_level == "director")
			{
				$occupationPoint = 3;
			}
			elseif($employment_level == "manager")
			{
				$occupationPoint = 2;
			}
			elseif($employment_level == "executive")
			{
				$occupationPoint = 1;
			}
			else
			{
				$occupationPoint = "error";
			}
			return $occupationPoint;
		}

		public function creditScore($age, $martial_status, $residential_status, $employment_status, $gross_salary, $employment_level)
		{
			$agePoint = $this->ageScore($age);
			$martialPoint = $this->martialScore($martial_status);
			//$dcPoint = $this->dependantScore($num_of_dc);
			$housingPoint = $this->housingScore($residential_status);
			$incomePoint = $this->incomeScore($employment_status);
			$salaryPoint = $this->salaryScore($gross_salary);
			$occupationPoint = $this->occupationScore($employment_level);

			$creditScore = $agePoint + $martialPoint  + $housingPoint + $incomePoint + $salaryPoint + $occupationPoint;
			return $creditScore;
		}

	}
?>